import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getOrders } from '@/apis/order'

export const useOrderStore = defineStore('order', () => {
    const orders = ref([])

    // 获取订单列表
    const fetchOrders = async () => {
        try {
            const res = await getOrders()
            orders.value = res
            return res
        } catch (error) {
            console.error('获取订单列表失败:', error)
            throw error
        }
    }

    return {
        orders,
        fetchOrders
    }
}, {
    persist: true
}) 